#-*- coding:utf-8 -*-

import requests
import hashlib
import  os
soft_path = "G:\\8910_V1.3\\hex\\AirM2M_720U_V301707_LTE_AT_TMP.zip"
hd  = open(soft_path,"rb")
soft = hd.read()
hd.close()
soft_md5  =   hashlib.md5(soft).hexdigest()

soft_map_path = "G:\\8910_V1.3\\hex\\AirM2M_720U_V301707_LTE_AT_TMP_MAP.zip"
hd  = open(soft_map_path,"rb")
soft_map = hd.read()
hd.close()
soft_map_md5  =   hashlib.md5(soft_map).hexdigest()

soft_ota_path = "G:\\8910_V1.3\\hex\\AirM2M_720U_V301707_LTE_AT_TMP\\AirM2M_720U_V301707_LTE_AT_TMP.dfota.bin"
hd  = open(soft_ota_path,"rb")
data_ota = hd.read()
hd.close()
data_ota_md5  =   hashlib.md5(data_ota).hexdigest()



header={'Api-Key':'2VjJxSU1WX8QSScTxFwfVGt6FcNVkZMr'}
# 以下为POST请求
url = 'http://erp.openluat.com/api/open/product_software'
postdatas = {'name': 'AirM2M_720U_V301677_LTE_AT_TMP' ,
             "info":"自动测试说明",
             "info_detail":"自动测试详细说明",
             "info_public":"自动测试详细说明",
             "usage":"临时版本",
             "code_path":"https://192.168.39.111/svn/RDA8910/branches/V1.3",
             "software_type":"8910",
             "software_type_2":"AT",
             "software_type_3":"标准AT",
             "product_ids":"1243,1335,1434",
             "software_md5":soft_md5,
             "bin_md5":data_ota_md5,
             "email":"liangjian@airm2m.com",
             "map_md5":soft_map_md5,
             "test_tool_md5":None,
             "self_test_report_md5":None
             }
files  = {
    "software":("AirM2M_720U_V301707_LTE_AT_TMP.zip",soft),
    "bin": ("AirM2M_720U_V301707_LTE_AT_TMP.dfota.bin",data_ota) ,
    "map": ("AirM2M_720U_V301707_LTE_AT_TMP_MAP.zip",soft_map)

}
requests = requests.post(url, data=postdatas,headers=header,files = files)
print(requests.status_code,requests.text.encode('utf-8').decode('gbk'))

# os.chdir("G:\\8910_V1.3")
# os.system('svn update')
# os.system('svn log')

# os.chdir("G:\\8910_V1.3")

